//
//  ComDynamicUI2VC.swift
//  ZYA
//
//  Created by 邱仙凯 on 2024/12/3.
//  Copyright © 2024 zwb. All rights reserved.
//

import UIKit
import JJCollectionViewRoundFlowLayout_Swift

class ComDynamicUI2VC: ComDynamicBaseVC {
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        navigationController?.setNavigationBarHidden(showNaviBar, animated: false)
        
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        
        navigationController?.setNavigationBarHidden(false, animated: false)
        
    }
    var showNaviBar = true
    var cv = ComDynNavView()
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if showNaviBar {
            
            cv.frame = CGRect(x: 0, y: -60, width: KSGlobal.screenW, height: 60)
            cv.titleLab.text = self.title
            cv.searchChange = { flag in
                if !flag {
                    self.keyWord = ""
                    self.searchBar!.text = ""
                    self.dealTempList()
                }
            }
            cv.backButton.addTouchUpInSideAction { _ in
                self.navigationController?.popViewController(animated: true)
            }
            cv.searchBg.addSubview(searchBar!)
            
            searchBar!.searchTextField.backgroundColor = UIColor.white
            searchBar?.backgroundImage = UIImage()
            searchBar!.placeholder = "搜索"
            searchBar!.searchTextField.layer.cornerRadius = 19
            searchBar!.searchTextField.layer.masksToBounds = true
            
            searchBar!.snp.makeConstraints { make in
                make.edges.equalToSuperview()
                
            }
            
            collectionView.addSubview(cv)
  
            collectionView.contentInset = UIEdgeInsets(top: 60, left: 0, bottom: 10, right: 0)
        } else {
            collectionView.contentInset = UIEdgeInsets(top: 15, left: 0, bottom: 10, right: 0)
        }
        
        collectionView.backgroundColor = .clear
        
        collectionView.register(BlockHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: BlockHeader.identifier)
        
        
        
        
        
    }
    
    override func addBg() {
        self.view.backgroundColor = Theme.commonBg
        let bgImg = UIImageView(image: UIImage(named: "common_bg"))
        bgImg.frame = self.view.bounds
        
        self.view.addSubview(bgImg)
    }
    
    override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
        
        let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: BlockHeader.identifier, for: indexPath) as! BlockHeader
        header.titleLabel.text = self.tempItemList[indexPath.section].0
        
        return header
        
        
        
    }
    
    override  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, borderEdgeInsertsForSectionAtIndex section: Int) -> UIEdgeInsets {
        return UIEdgeInsets.init(top: -5, left: newModuleLeading, bottom: 12, right: newModuleLeading)
    }
    override  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, configModelForSectionAtIndex section: Int) -> JJCollectionViewRoundConfigModel_Swift {
        
        
        let model = JJCollectionViewRoundConfigModel_Swift.init()
        model.cornerRadius = 8
        model.backgroundColor = UIColor.white
        return model
        
        
    }
    
    override func getcolltopMargin() -> CGFloat {
        return 0
    }
}

